<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>短信验证倒计时</title>
    <style>
       
    </style>
</head>
<body>
    <div id="container">
        <p>绑定用户信息！</p>

        <div>
            <label for="phone">手机号：</label>
            <input type="text" id="phone" name="phone">
            <button id="send-code" onclick="checkPhone()">发送验证码</button>
        </div>
        <div>
            <label for="code">验证码：</label>
            <input type="text" id="code" name="code">
            <button id="check-code" onclick="checkCode()">验证</button>
        </div>
    </div>


    <script>
        
        // 发送验证码倒计时
        function sendCode() {
            var time = 10;
            var btn = document.getElementById('send-code');
            btn.disabled = true;
            btn.innerHTML = time + '秒后重发';
            var timer = setInterval(function() {
                time--;
                btn.innerHTML = time + '秒后重发';
                if (time <= 0) {
                    clearInterval(timer);
                    btn.disabled = false;
                    btn.innerHTML = '重新发送';
                }
            }, 1000);
        }

        // 手机号验证
        function checkPhone() {
            var phone = document.getElementById('phone').value;
            var reg = /^1[3456789]\d{9}$/;
            if (!reg.test(phone)) {
                alert('手机号格式错误');
                return false;
            }
            sendCode();
        }

        // 验证码验证
        function checkCode() {
            var code = document.getElementById('code').value;
            var reg = /^\d{6}$/;
            if (!reg.test(code)) {
                alert('验证码格式错误');
                return false;
            }
            // 验证通过，提交表单
            // document.getElementById('form').submit();
            alert('验证通过');
        }
    </script>
</body>
</html>